import React, {Component} from 'react';
import PropTypes from 'prop-types'
import {Card, WhiteSpace,WingBlank} from 'antd-mobile'
import { withRouter } from 'react-router-dom'

@withRouter
export default class UserCard extends Component {
   static propTypes={
       userList:PropTypes.array.isRequired
   }
   handleClick=(v)=>{
       this.props.history.push(`/chat/${v.user}`)
   }

    render() {
        return (
        <WingBlank>
            <WhiteSpace></WhiteSpace>
            {this.props.userList?this.props.userList.map(v=>(
                v.avatar?(
                <Card key={v._id} onClick={()=>this.handleClick(v)}>
                    <Card.Header
                     title={v.user}
                     thumb={require(`../img/${v.avatar}.png`)}
                     extra={<span>{v.title}</span>}
                    >
                    </Card.Header>
                    <Card.Body>
                        {v.type==='boss'?<div>{v.company}</div>:null}
                        {v.desc?(v.desc.split('\n').map(d=>(
                            <div key={d}>{d}</div>
                        ))):null}
                        {v.type==='boss'?<div>{v.money}</div>:null}
                    </Card.Body>
                </Card>):null

            )):null}
        </WingBlank>
        );
    }
}